import { export_json_to_excel } from "./Export2Excel";

// 导出Excel
export function export2Excel(columns, _data, _name) {
    require.ensure([], () => {

        // 设置表头
        let tHeader = [];
        // 设置属性
        let filterVal = [];
        columns.forEach((element) => {
            tHeader.push(element.title);
            filterVal.push(element.dataIndex);
        })

        const list = _data;
        const data1 = formatJson(filterVal, list);

        export_json_to_excel(
            tHeader,
            data1,
            _name
        );
    });
}

function formatJson(filterVal, jsonData) {
    return jsonData.map((v) => filterVal.map((j) => v[j]));
}
